use mime_guess2::MimeGuess;
use std::sync::Arc;

pub fn get_icon_for_mime(mime: &str) -> Arc<str> {
    let file_name = match mime {
        "android/package-archive" => "android-package-archive.svg",
        "application/vnd.android.package-archive" => "android-package-archive.svg",
        "application/apk" => "application-apk.svg",
        "application/ascii" => "application-ascii.svg",
        "application/audio" => "application-audio.svg",
        "application/audio-playlist" => "application-audio-playlist.svg",
        "application/blank" => "application-blank.svg",
        "application/certificate" => "application-certificate.svg",
        "application/com.github.phase1geo.minder" => "application-com.github.phase1geo.minder.svg",
        "application/dicom" => "application-dicom.svg",
        "application/document" => "application-document.svg",
        "application/document-template" => "application-document-template.svg",
        "application/drawing-template" => "application-drawing-template.svg",
        "application/epub+zip" => "application-epub+zip.svg",
        "application/illustrator" => "application-illustrator.svg",
        "application/image-bmp" => "application-image-bmp.svg",
        "application/image-gif" => "application-image-gif.svg",
        "application/image-ico" => "application-image-ico.svg",
        "application/image-jpg" => "application-image-jpg.svg",
        "application/image-tga" => "application-image-tga.svg",
        "application/image-tiff" => "application-image-tiff.svg",
        "application/info" => "application-info.svg",
        "application/json" => "application-json.svg",
        "application/mathematica" => "application-mathematica.svg",
        "application/mbox" => "application-mbox.svg",
        "application/msonenote" => "application-msonenote.svg",
        "application/msoutlook" => "application-msoutlook.svg",
        "application/msword-template" => "application-msword-template.svg",
        "application/octet-stream" => "application-octet-stream.svg",
        "application/ogg" => "application-ogg.svg",
        "application/ovf" => "application-ovf.svg",
        "application/pdf" => "application-pdf.svg",
        "application/pgp" => "application-pgp.svg",
        "application/pgp-signature" => "application-pgp-signature.svg",
        "application/photoshop" => "application-photoshop.svg",
        "application/postscript" => "application-postscript.svg",
        "application/presentation-template" => "application-presentation-template.svg",
        "application/rss_xml" => "application-rss_xml.svg",
        "application/script-blank" => "application-script-blank.svg",
        "application/software" => "application-software.svg",
        "application/sql" => "application-sql.svg",
        "application/table-template" => "application-table-template.svg",
        "application/text-template" => "application-text-template.svg",
        "application/torrent" => "application-torrent.svg",
        "application/users" => "application-users.svg",
        "application/vector" => "application-vector.svg",
        "application/vector-template" => "application-vector-template.svg",
        "application/vnd.appimage" => "application-vnd.appimage.svg",
        "application/vnd.apple.pkpass" => "application-vnd.apple.pkpass.svg",
        "application/vnd.coffeescript" => "application-vnd.coffeescript.svg",
        "application/vnd.efi.iso" => "application-vnd.efi.iso.svg",
        "application/vnd.flatpak" => "application-vnd.flatpak.svg",
        "application/vnd.flatpak.ref" => "application-vnd.flatpak.ref.svg",
        "application/vnd.geogebra.file" => "application-vnd.geogebra.file.svg",
        "application/vnd.iccprofile" => "application-vnd.iccprofile.svg",
        "application/vnd.kde.bluedevil-sendfile" => "application-vnd.kde.bluedevil-sendfile.svg",
        "application/vnd.microsoft.portable-executable" => {
            "application-vnd.microsoft.portable-executable.svg"
        }
        "application/vnd.ms-access" => "application-vnd.ms-access.svg",
        "application/vnd.ms-cab-compressed" => "application-vnd.ms-cab-compressed.svg",
        "application/vnd.ms-excel" => "application-vnd.ms-excel.svg",
        "application/vnd.ms-excel.template.macroenabled.12" => {
            "application-vnd.ms-excel.template.macroenabled.12.svg"
        }
        "application/vnd.ms-htmlhelp" => "application-vnd.ms-htmlhelp.svg",
        "application/vnd.ms-infopath" => "application-vnd.ms-infopath.svg",
        "application/vnd.ms-powerpoint" => "application-vnd.ms-powerpoint.svg",
        "application/vnd.ms-powerpoint.template.macroenabled.12" => {
            "application-vnd.ms-powerpoint.template.macroenabled.12.svg"
        }
        "application/vnd.ms-publisher" => "application-vnd.ms-publisher.svg",
        "application/vnd.ms-word" => "application-vnd.ms-word.svg",
        "application/vnd.nokia.xml.qt.resource" => "application-vnd.nokia.xml.qt.resource.svg",
        "application/vnd.oasis.opendocument.chart" => {
            "application-vnd.oasis.opendocument.chart.svg"
        }
        "application/vnd.oasis.opendocument.chart-template" => {
            "application-vnd.oasis.opendocument.chart-template.svg"
        }
        "application/vnd.oasis.opendocument.formula" => {
            "application-vnd.oasis.opendocument.formula.svg"
        }
        "application/vnd.oasis.opendocument.formula-template" => {
            "application-vnd.oasis.opendocument.formula-template.svg"
        }
        "application/vnd.oasis.opendocument.presentation-template" => {
            "application-vnd.oasis.opendocument.presentation-template.svg"
        }
        "application/vnd.oasis.opendocument.spreadsheet-template" => {
            "application-vnd.oasis.opendocument.spreadsheet-template.svg"
        }
        "application/vnd.oasis.opendocument.text-template" => {
            "application-vnd.oasis.opendocument.text-template.svg"
        }
        "application/vnd.oasis.opendocument.web-template" => {
            "application-vnd.oasis.opendocument.web-template.svg"
        }
        "application/vnd.openxmlformats-officedocument.spreadsheetml.template" => {
            "application-vnd.openxmlformats-officedocument.spreadsheetml.template.svg"
        }
        "application/vnd.openxmlformats-officedocument.wordprocessingml.template" => {
            "application-vnd.openxmlformats-officedocument.wordprocessingml.template.svg"
        }
        "application/vnd.scribus" => "application-vnd.scribus.svg",
        "application/vnd.snap" => "application-vnd.snap.svg",
        "application/vnd.visio" => "application-vnd.visio.svg",
        "application/web-template" => "application-web-template.svg",
        "application/word-template" => "application-word-template.svg",
        "application/x-ace" => "application-x-ace.svg",
        "application/x-addon" => "application-x-addon.svg",
        "application/x-alpm-package" => "application-x-alpm-package.svg",
        "application/x-ar" => "application-x-ar.svg",
        "application/x-arc" => "application-x-arc.svg",
        "application/x-archive" => "application-x-archive.svg",
        "application/x-arj" => "application-x-arj.svg",
        "application/x-bat" => "application-x-bat.svg",
        "application/x-bittorrent" => "application-x-bittorrent.svg",
        "application/x-blender" => "application-x-blender.svg",
        "application/x-bzdvi" => "application-x-bzdvi.svg",
        "application/x-bzip" => "application-x-bzip.svg",
        "application/x-bzip-compressed-tar" => "application-x-bzip-compressed-tar.svg",
        "application/x-cd-image" => "application-x-cd-image.svg",
        "application/x-chm" => "application-x-chm.svg",
        "application/x-clementine" => "application-x-clementine.svg",
        "application/x-compressed-tar" => "application-x-compressed-tar.svg",
        "application/x-deb" => "application-x-deb.svg",
        "application/x-designer" => "application-x-designer.svg",
        "application/x-desktop" => "application-x-desktop.svg",
        "application/x-executable" => "application-x-executable.svg",
        "application/x-fictionbook+xml" => "application-x-fictionbook+xml.svg",
        "application/x-firmware" => "application-x-firmware.svg",
        "application/x-flash-video" => "application-x-flash-video.svg",
        "application/x-freeplane" => "application-x-freeplane.svg",
        "application/x-gdscript" => "application-x-gdscript.svg",
        "application/x-godot-project" => "application-x-godot-project.svg",
        "application/x-godot-resource" => "application-x-godot-resource.svg",
        "application/x-godot-scene" => "application-x-godot-scene.svg",
        "application/x-godot-shader" => "application-x-godot-shader.svg",
        "application/x-gzip" => "application-x-gzip.svg",
        "application/x-gzpostscript" => "application-x-gzpostscript.svg",
        "application/x-java" => "application-x-java.svg",
        "application/x-java-archive" => "application-x-java-archive.svg",
        "application/x-kdenlivetitle" => "application-x-kdenlivetitle.svg",
        "application/x-kexi-connectiondata" => "application-x-kexi-connectiondata.svg",
        "application/x-kexiproject-shortcut" => "application-x-kexiproject-shortcut.svg",
        "application/x-kmymoney" => "application-x-kmymoney.svg",
        "application/x-kplato" => "application-x-kplato.svg",
        "application/x-kvtml" => "application-x-kvtml.svg",
        "application/x-labplot2" => "application-x-labplot2.svg",
        "application/x-lrzip" => "application-x-lrzip.svg",
        "application/x-lrzip-compressed-tar" => "application-x-lrzip-compressed-tar.svg",
        "application/x-lzip" => "application-x-lzip.svg",
        "application/x-lzma-compressed-tar" => "application-x-lzma-compressed-tar.svg",
        "application/x-lzop" => "application-x-lzop.svg",
        "application/x-macbinary" => "application-x-macbinary.svg",
        "application/x-marble" => "application-x-marble.svg",
        "application/x-mobipocket-ebook" => "application-x-mobipocket-ebook.svg",
        "application/x-ms-dos-executable" => "application-x-ms-dos-executable.svg",
        "application/x-ms-shortcut" => "application-x-ms-shortcut.svg",
        "application/x-ms-wim" => "application-x-ms-wim.svg",
        "application/x-msdownload" => "application-x-msdownload.svg",
        "application/x-object" => "application-x-object.svg",
        "application/x-osm+xml" => "application-x-osm+xml.svg",
        "application/x-partial-download" => "application-x-partial-download.svg",
        "application/x-pem-key" => "application-x-pem-key.svg",
        "application/x-perl" => "application-x-perl.svg",
        "application/x-plasma" => "application-x-plasma.svg",
        "application/x-rar" => "application-x-rar.svg",
        "application/x-remote-connection" => "application-x-remote-connection.svg",
        "application/x-renderdoc-capture" => "application-x-renderdoc-capture.svg",
        "application/x-root" => "application-x-root.svg",
        "application/x-rpm" => "application-x-rpm.svg",
        "application/x-ruby" => "application-x-ruby.svg",
        "application/x-sharedlib" => "application-x-sharedlib.svg",
        "application/x-shellscript" => "application-x-shellscript.svg",
        "application/x-skg" => "application-x-skg.svg",
        "application/x-skgc" => "application-x-skgc.svg",
        "application/x-smb-workgroup" => "application-x-smb-workgroup.svg",
        "application/x-sogouskin" => "application-x-sogouskin.svg",
        "application/x-srt" => "application-x-srt.svg",
        "application/x-subrip" => "application-x-subrip.svg",
        "application/x-tar" => "application-x-tar.svg",
        "application/x-tarz" => "application-x-tarz.svg",
        "application/x-tha" => "application-x-tha.svg",
        "application/x-theme" => "application-x-theme.svg",
        "application/x-thz" => "application-x-thz.svg",
        "application/x-trash" => "application-x-trash.svg",
        "application/x-tzo" => "application-x-tzo.svg",
        "application/x-wine-extension-cpl" => "application-x-wine-extension-cpl.svg",
        "application/x-wine-extension-skb" => "application-x-wine-extension-skb.svg",
        "application/x-wine-extension-skp" => "application-x-wine-extension-skp.svg",
        "application/x-xar" => "application-x-xar.svg",
        "application/x-xopp" => "application-x-xopp.svg",
        "application/x-xz" => "application-x-xz-compressed-tar.svg",
        "application/x-xz-compressed-tar" => "application-x-xz-compressed-tar.svg",
        "application/x-yaml" => "application-x-yaml.svg",
        "application/x-zip" => "application-x-zip.svg",
        "application/x-zstd-compressed-tar" => "application-x-zstd-compressed-tar.svg",
        "application/x-7z-compressed" => "application-x-zip.svg",
        "application/xmind" => "application-xmind.svg",
        "application/zstd" => "application-zstd.svg",
        "application/tar" => "application-x-tar.svg",
        "application/zip" => "application-x-zip.svg",
        "audio/midi" => "audio-midi.svg",
        "audio/x-generic" => "audio-x-generic.svg",
        "audio/x-mp3-playlist" => "audio-x-mp3-playlist.svg",
        "extension" => "extension.svg",
        "font/x-generic" => "font-x-generic.svg",
        "gddoc" => "gddoc.svg",
        "gddraw" => "gddraw.svg",
        "gdform" => "gdform.svg",
        "gdlink" => "gdlink.svg",
        "gdnote" => "gdnote.svg",
        "gdscript" => "gdscript.svg",
        "gdsheet" => "gdsheet.svg",
        "gdslides" => "gdslides.svg",
        "image/jpg" => "application-image-jpg.svg",
        "image/jpeg" => "application-image-jpg.svg",
        "image/png" => "image-png.svg",
        "image/svg+xml" => "image-svg+xml.svg",
        "image/vnd.dgn" => "image-vnd.dgn.svg",
        "image/vnd.djvu" => "image-vnd.djvu.svg",
        "image/vnd.dwg" => "image-vnd.dwg.svg",
        "image/webp" => "image-webp.svg",
        "image/x-compressed-xcf" => "image-x-compressed-xcf.svg",
        "image/x-generic" => "image-x-generic.svg",
        "inode/symlink" => "inode-symlink.svg",
        "libreoffice/oasis-database" => "libreoffice-oasis-database.svg",
        "libreoffice/oasis-drawing" => "libreoffice-oasis-drawing.svg",
        "libreoffice/oasis-formula" => "libreoffice-oasis-formula.svg",
        "libreoffice/oasis-master-document" => "libreoffice-oasis-master-document.svg",
        "libreoffice/oasis-presentation" => "libreoffice-oasis-presentation.svg",
        "libreoffice/oasis-spreadsheet" => "libreoffice-oasis-spreadsheet.svg",
        "libreoffice/oasis-text" => "libreoffice-oasis-text.svg",
        "libreoffice/oasis-web" => "libreoffice-oasis-web.svg",
        "message/news" => "message-news.svg",
        "message/partial" => "message-partial.svg",
        "message/rfc822" => "message-rfc822.svg",
        "office/contact" => "office-contact.svg",
        "package/x-generic" => "package-x-generic.svg",
        "stock_addressbook" => "stock_addressbook.svg",
        "system/component-addon" => "system-component-addon.svg",
        "system/component-codecs" => "system-component-codecs.svg",
        "system/component-driver" => "system-component-driver.svg",
        "system/component-input-sources" => "system-component-input-sources.svg",
        "system/component-language" => "system-component-language.svg",
        "system/component-os-updates" => "system-component-os-updates.svg",
        "system/component-runtime" => "system-component-runtime.svg",
        "text/css" => "text-css.svg",
        "text/dockerfile" => "text-dockerfile.svg",
        "text/html" => "text-html.svg",
        "text/less" => "text-less.svg",
        "text/markdown" => "text-markdown.svg",
        "text/richtext" => "text-richtext.svg",
        "text/rust" => "text-rust.svg",
        "text/vnd.trolltech.linguist" => "text-vnd.trolltech.linguist.svg",
        "text/wiki" => "text-wiki.svg",
        "text/x-adasrc" => "text-x-adasrc.svg",
        "text/x-apport" => "text-x-apport.svg",
        "text/x-authors" => "text-x-authors.svg",
        "text/x-c" => "text-x-c.svg",
        "text/x-c++hdr" => "text-x-c++hdr.svg",
        "text/x-changelog" => "text-x-changelog.svg",
        "text/x-chdr" => "text-x-chdr.svg",
        "text/x-cmake" => "text-x-cmake.svg",
        "text/x-cobol" => "text-x-cobol.svg",
        "text/x-copying" => "text-x-copying.svg",
        "text/x-cpp" => "text-x-cpp.svg",
        "text/x-csharp" => "text-x-csharp.svg",
        "text/x-emacs-lisp" => "text-x-emacs-lisp.svg",
        "text/x-fortran" => "text-x-fortran.svg",
        "text/x-generic" => "text-x-generic.svg",
        "text/x-gettext-translation" => "text-x-gettext-translation.svg",
        "text/x-go" => "text-x-go.svg",
        "text/x-haskell" => "text-x-haskell.svg",
        "text/x-hex" => "text-x-hex.svg",
        "text/x-install" => "text-x-install.svg",
        "text/x-java" => "text-x-java.svg",
        "text/x-javascript" => "text-x-javascript.svg",
        "text/x-kotlin" => "text-x-kotlin.svg",
        "text/x-kvt" => "text-x-kvt.svg",
        "text/x-lua" => "text-x-lua.svg",
        "text/x-makefile" => "text-x-makefile.svg",
        "text/x-pascal" => "text-x-pascal.svg",
        "text/x-patch" => "text-x-patch.svg",
        "text/x-php" => "text-x-php.svg",
        "text/x-po" => "text-x-po.svg",
        "text/x-preview" => "text-x-preview.svg",
        "text/x-python" => "text-x-python.svg",
        "text/x-qml" => "text-x-qml.svg",
        "text/x-r" => "text-x-r.svg",
        "text/x-readme" => "text-x-readme.svg",
        "text/x-rpm-spec" => "text-x-rpm-spec.svg",
        "text/x-ruby" => "text-x-ruby.svg",
        "text/x-sass" => "text-x-sass.svg",
        "text/x-scala" => "text-x-scala.svg",
        "text/x-script" => "text-x-script.svg",
        "text/x-sql" => "text-x-sql.svg",
        "text/x-tcl" => "text-x-tcl.svg",
        "text/x-tex" => "text-x-tex.svg",
        "text/x-typescript" => "text-x-typescript.svg",
        "text/x-vala" => "text-x-vala.svg",
        "text/xml" => "text-xml.svg",
        "video/x-generic" => "video-x-generic.svg",
        "video/mp4" => "video-x-generic.svg",
        "video/quicktime" => "video-x-generic.svg",
        "virtualbox/hdd" => "virtualbox-hdd.svg",
        "virtualbox/ova" => "virtualbox-ova.svg",
        "virtualbox/ovf" => "virtualbox-ovf.svg",
        "virtualbox/vbox" => "virtualbox-vbox.svg",
        "virtualbox/vbox-extpack" => "virtualbox-vbox-extpack.svg",
        "virtualbox/vdi" => "virtualbox-vdi.svg",
        "virtualbox/vhd" => "virtualbox-vhd.svg",
        "virtualbox/vmdk" => "virtualbox-vmdk.svg",
        "x/content-software" => "x-content-software.svg",
        "x/kde-nsplugin-generated" => "x-kde-nsplugin-generated.svg",
        "x/media-podcast" => "x-media-podcast.svg",
        "x/office-calendar" => "x-office-calendar.svg",
        "x/office-document" => "x-office-document.svg",
        "x/office-presentation" => "x-office-presentation.svg",
        "x/office-spreadsheet" => "x-office-spreadsheet.svg",
        "x/package-repository" => "x-package-repository.svg",
        "unknown" => "unknown.svg",
        _ => "unknown.svg",
    };
    format!("icons/mimes/{}", file_name).into()
}

/// Detect mime type for file in file system (Disk Access)
pub fn detect_mime_type(file_path: &str) -> String {
    infer::get_from_path(file_path)
        .unwrap()
        .map(|k| k.mime_type().to_string())
        .unwrap_or_else(|| {
            if let Some(mime) = MimeGuess::from_path(file_path).first() {
                mime.to_string()
            } else {
                "unknown".to_string()
            }
        })
}
